package com.wwh.furn.bean;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Albert
 * @date 2024/12/19-20:46
 * @describe 客户端程序返回给前端的json数据的Msg对象
 */
public class Msg {
    //状态码 200-成功 400-失败
    private int code;
    //信息
    private String msg;
    //返回给客户端或者浏览器
    private Map<String, Object> extend = new HashMap<String, Object>();

    //编写几个常用的方法
    //返回成功对应的Msg
    public static Msg success() {
        Msg msg = new Msg();
        msg.setCode(200);
        msg.setMsg("success");
        return msg;
    }

    //返回失败对应的Msg
    public static Msg fail() {
        Msg msg = new Msg();
        msg.setCode(400);
        msg.setMsg("fail");
        return msg;
    }

    //给返回的Msg设置数据
    public Msg add(String key, Object value) {
        this.extend.put(key, value);
        return this;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Map<String, Object> getExtend() {
        return extend;
    }

    public void setExtend(Map<String, Object> extend) {
        this.extend = extend;
    }

    public int getCode() {
        return code;
    }
}
